<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb>
      <el-breadcrumb-item>关系信息录入</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表单输入 -->
    <div class="ConnectionFormBox">
      <el-form ref="ConnectionFormRef" :model="ConnectionForm" :rules="ConnectionFormRules" class="ConnectionForm_sty">
        <el-form-item prop="id">
          <el-input v-model="ConnectionForm.id">
            <template slot="prepend">关系ID</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="c_one">
          <el-input v-model="ConnectionForm.one">
            <template slot="prepend">成员1</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="c_two">
          <el-input v-model="ConnectionForm.two">
            <template slot="prepend">成员2</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="c_connect">
          <el-input v-model="ConnectionForm.connect">
            <template slot="prepend">关系</template>
          </el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="inserUser" round>录入</el-button>
          <el-button type="info" @click="resetConnectionForm" round>重置</el-button>
        </el-form-item>
      </el-form>
      <!-- 提交弹窗 -->
      <el-dialog title="提示" :visible.sync="sucessVisible" width="30%">
        <span>确定录入？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="sucessVisible = false">取 消</el-button>
          <el-button type="primary" @click="sucessVisible = false">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ConnectionForm: {
        id: '',
        one: '',
        two: '',
        connect: ''
      },
      // 输入规则
      ConnectionFormRules: {
        id: [
          { required: true, message: '请输入关系ID', trigger: 'blur' }
        ],
        one: [
          { required: true, message: '请输入成员1', trigger: 'blur' }
        ],
        two: [
          { required: true, message: '请输入成员2', trigger: 'blur' }
        ],
        ship: [
          { required: true, message: '请输入关系', trigger: 'blur' }
        ]
      },
      sucessVisible: false
    }
  },
  methods: {
    // 校验规则
    resetConnectionForm() {
      this.$refs.ConnectionFormRef.resetFields()
    },
    // 提交用户
    inserUser() {
      const { data: res } = this.$http.post('connection', {
        c_id: this.ConnectionForm.id,
        c_one: this.ConnectionForm.one,
        c_two: this.ConnectionForm.two,
        c_connect: this.ConnectionForm.connect
      })
      this.emidtsucess()
      console.log(res)
    },
    // 提交成功提示
    emidtsucess() {
      this.sucessVisible = true
    }
  }
}
</script>

<style lang="less" scoped>
.el-form-item {
  width: 500px;
}

.ConnectionFormBox {
  background-color: #fffffb;
  height: 600px;
  width: 1210px;
  border-radius: 5px;
  margin-left: 10px;
}

.ConnectionForm_sty {
  position: absolute;
  padding: 30px 60px 30px;
  box-sizing: border-box;
}

.btns {
  display: flex;
  justify-content: flex-start;
  margin-top: 60px;
}
</style>
